//$store.state.user.userinfo 获取
import store from "ui/utils/store.js";
import Vue from "vue";
export default {
    state:{
        userinfo:store.getItem('userinfo') || {},
    },
    actions:{
        user_update({commit},{data}){
            return new Promise((resolve,reject)=>{
                commit('user_update',{
                    data
                })
                resolve();
            })
        },user_remove({commit}){
            return new Promise((resolve,reject)=>{
                commit('user_remove')
                resolve();
            })
        } 
    },
    mutations:{
        user_update:(state,{data})=>{
            state.userinfo=data || {};
            store.setItem('userinfo',data,data.exp || 60)
        },
        user_remove:(state)=>{
            state.userinfo={};
            store.removeItem('userinfo')
        }   
    },getters:{
        getUser(state){
            return state.userinfo;
        },
        getToken(state){
            return state.userinfo.token?state.userinfo.token:'';
        },getStatus(state){
            return state.userinfo.name?true:false;
        }
    }
}